package com.ybkj.daijia.template.em;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.core.io.support.PropertiesLoaderUtils;

public class FreightFunctionTag implements TemplateDirectiveModel {


    @Override
    public void execute(Environment env, Map params, TemplateModel[] model,
        TemplateDirectiveBody body) throws TemplateException, IOException {

        Properties properties = PropertiesLoaderUtils
            .loadAllProperties("config.properties", PartnerFunctionTag.class.getClassLoader());

        boolean show = BooleanUtils
            .toBoolean(properties.getProperty("function.freight.open", "false"));

        if (show) {
            renderBody(env, body);
        }

    }

    protected void renderBody(Environment env, TemplateDirectiveBody body)
        throws IOException, TemplateException {
        if (body != null) {
            body.render(env.getOut());
        }
    }
}
